from django.db import models
from login.models import Users



#房源城市表
class House_city(models.Model):
     city=models.CharField(max_length=20,verbose_name='城市')
     #自关联
     pid=models.ForeignKey('self',on_delete=models.CASCADE,verbose_name='父级id',blank=True,null=True)
     class Meta:
         db_table='house_city'
         verbose_name='房源城市表'


#房源表
class House(models.Model):
     title=models.CharField(max_length=20,verbose_name='房产标题')
     #所属城市
     city=models.ForeignKey(House_city,on_delete=models.CASCADE,verbose_name='所属城市')
     #所属城市父类
     city_pid=models.ForeignKey(House_city,on_delete=models.CASCADE,related_name='city_pid',verbose_name='所属城市父类')
     district=models.CharField(max_length=20,verbose_name='所在区域')
     address=models.CharField(max_length=30,verbose_name='详细地址')
     price=models.DecimalField(max_digits=10,decimal_places=2,verbose_name='价格')
     rooms=models.CharField(max_length=20,verbose_name='户型')
     area=models.DecimalField(max_digits=10,decimal_places=2,verbose_name='面积')
     property_type=models.CharField(max_length=20,verbose_name='房产类型')
     is_rented=models.BooleanField(verbose_name='是否出租')
     is_sold=models.BooleanField(verbose_name='是否出售')
     direction=models.CharField(max_length=20,verbose_name='朝向')
     date=models.CharField(max_length=10,verbose_name='年代')
     deposit=models.DecimalField(max_digits=10,decimal_places=2,verbose_name='首付')
     desc=models.TextField(verbose_name='描述')
     class Meta:
         db_table='house'
         verbose_name='房源表'
     def __str__(self):
         return self.title

#用户浏览记录表
class User_record(models.Model):
     user=models.ForeignKey(Users,on_delete=models.CASCADE,verbose_name='用户')
     house=models.ForeignKey(House,on_delete=models.CASCADE,verbose_name='房源')
     city_pid=models.ForeignKey(House_city,on_delete=models.CASCADE,related_name='citypid',verbose_name='所属城市父类')
     count=models.IntegerField(verbose_name='浏览次数')
     class Meta:
         db_table='user_record'
         verbose_name='用户浏览记录表'